﻿Imports System
Imports System.IO
Imports System.Data.SqlServerCe
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.Common
Imports System.Reflection

Public Class frmCreateCoupon

    Sub initScreen()
        loadWeldSizeForCbo(_USER_ID, cboCreateCouponSize)
        loadMaterialForCbo(cboCreateCouponMaterial)
        findSystemTypeForListing(lvCouponSystemType)

        loadHeatNoForCbo(cboCreateCouponHeat1, cboCreateCouponHeat2)
        loadJointTypeForCbo(cboCreateCouponJointType1, cboCreateCouponJointType2)
        loadWeldMachineForCbo(cboCreateCouponWeldMachine)

        btnSaveCoupon.Text = "Save"
        txtCreateCouponNo.Text = ""
        txtCreateCouponBarcode.Text = ""
        cboCreateCouponSize.DropDownStyle = ComboBoxStyle.DropDownList

        Me.tabCreateCoupon.SelectedIndex = 0
        Me.tabCreateCoupon.Refresh()

        If (Globals.USER_ROLE_WELDER = _USER_ROLE) Then
            btnSaveCoupon.Location = New System.Drawing.Point(19, btnSaveCoupon.Location.Y)
            btnCancelCoupon.Location = New System.Drawing.Point(121, btnCancelCoupon.Location.Y)

            btnSaveCoupon.Size = New System.Drawing.Size(91, 23)
            btnCancelCoupon.Size = New System.Drawing.Size(91, 23)
            btnDeleteCoupon.Hide()
        ElseIf (Globals.USER_ROLE_ENGINEER = _USER_ROLE) Then
            btnSaveCoupon.Location = New System.Drawing.Point(19, btnSaveCoupon.Location.Y)
            btnCancelCoupon.Location = New System.Drawing.Point(153, btnCancelCoupon.Location.Y)
            btnDeleteCoupon.Location = New System.Drawing.Point(87, btnCancelCoupon.Location.Y)

            btnSaveCoupon.Size = New System.Drawing.Size(59, 23)
            btnCancelCoupon.Size = New System.Drawing.Size(59, 23)
            btnDeleteCoupon.Size = New System.Drawing.Size(59, 23)

            btnDeleteCoupon.Show()
        End If
    End Sub

    Public Sub editCoupon(ByVal couponId As String)
        Dim dtResult As New DataTable
        dtResult = findEngineerCoupons(_PROJECT_ID, vbNullString, vbNullString, vbNullString, couponId, vbNullString, vbNullString)

        If dtResult.Rows.Count > 0 Then
            Dim dataRow As DataRow = dtResult.Rows(0)
            _COUPON_ID = couponId
            _COUPON_BARCODE = dataRow.Item("BARCODE").ToString

            'loadSizeForCbo(_PROJECT_ID, cboWeldARSize, Nothing)

            If (Globals.USER_ROLE_WELDER = _USER_ROLE) Then
                loadWeldSizeForCbo(_USER_ID, cboCreateCouponSize)
            ElseIf (Globals.USER_ROLE_ENGINEER = _USER_ROLE) Then
                cboCreateCouponSize.DropDownStyle = ComboBoxStyle.DropDown
            End If

            'loadThicknessForCbo(_PROJECT_ID, cboWeldARThickness, cboCreateCouponThickness)

            'loadMaterialForCbo(cboCreateCouponMaterial)
            cboCreateCouponWeldMachine.Text = dataRow.Item("WELD_MACHINE_NAME")
            txtCreateCouponNo.Text = dataRow.Item("COUPON_CODE")
            cboCreateCouponCoax.Text = dataRow.Item("COAX")
            cboCreateCouponMaterial.Text = dataRow.Item("MATERIAL")
            cboCreateCouponSize.Text = dataRow.Item("SIZE")
            cboCreateCouponThickness.Text = dataRow.Item("THICKNESS")
            cboCreateCouponHeat1.Text = dataRow.Item("HEAT_NUMBER_NAME_1")
            cboCreateCouponHeat2.Text = dataRow.Item("HEAT_NUMBER_NAME_2")
            cboCreateCouponJointType1.Text = dataRow.Item("JOINT_TYPE_NAME_1")
            cboCreateCouponJointType2.Text = dataRow.Item("JOINT_TYPE_NAME_2")
            txtCreateCouponBarcode.Text = dataRow.Item("BARCODE")

            If (_ACTION = Globals.BUTTON_LABEL_EDIT) Then
                btnSaveCoupon.Text = Globals.BUTTON_LABEL_UPDATE
            ElseIf (_ACTION = Globals.BUTTON_LABEL_REDO) Then
                btnSaveCoupon.Text = Globals.BUTTON_LABEL_REDO
                txtCreateCouponBarcode.Text = ""
            End If

            Dim pipeTube As String = dataRow.Item("PIPE_TUBE")
            Dim isCoax As String = dataRow.Item("IS_COAX")

            If (isCoax = "T") Then
                chkCreateCouponCoax.Checked = True
            Else
                chkCreateCouponCoax.Checked = False
            End If

            If pipeTube = "PIPE" Then
                rdoCreateCouponPipe.Checked = True
            ElseIf pipeTube = "TUBE" Then
                rdoCreateCouponTube.Checked = True
            End If

            Dim couponSystemDtResult As New DataTable
            couponSystemDtResult = findCouponSystems(couponId)
            Dim lstItem As ListViewItem
            'uncheck all items
            For Each lstItem In lvCouponSystemType.Items
                lstItem.Checked = False
            Next

            If couponSystemDtResult.Rows.Count > 0 Then
                For Each couponSystemDataRow As DataRow In couponSystemDtResult.Rows
                    For Each lstItem In lvCouponSystemType.Items
                        If (lstItem.Tag = couponSystemDataRow.Item("SYSTEM_TYPE_ID")) Then
                            lstItem.Checked = True
                            Exit For
                        Else
                            'lstItem.Checked = False
                        End If
                    Next
                Next
            End If
        Else
            MsgBox("Invalid Action (ERR001)", MsgBoxStyle.Exclamation, "EQAM")
        End If
    End Sub

    Private Sub btnSaveCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveCoupon.Click
        ' save coupon        
        Dim returnExecute As Boolean = False

        If (btnSaveCoupon.Text = Globals.BUTTON_LABEL_UPDATE) Then
            If (txtCreateCouponBarcode.Text <> "" And checkBarcodeDuplication(txtCreateCouponBarcode.Text, _COUPON_ID)) Then
                MsgBox(txtCreateCouponBarcode.Text & " alraedy exists.", MsgBoxStyle.Information, "EQAM")
                Me.tabCreateCoupon.SelectedIndex = 0
                Me.tabCreateCoupon.Refresh()
                Return
            End If
        Else
            If (txtCreateCouponBarcode.Text <> "" And checkBarcodeDuplication(txtCreateCouponBarcode.Text, Nothing)) Then
                MsgBox(txtCreateCouponBarcode.Text & " alraedy exists.", MsgBoxStyle.Information, "EQAM")
                Me.tabCreateCoupon.SelectedIndex = 0
                Me.tabCreateCoupon.Refresh()
                Return
            End If
        End If        

        Dim pipeTube As String = ""
        Dim isCoax As String = "F"


        Dim lstItem As ListViewItem
        Dim itemChecked As Boolean = False
        For Each lstItem In lvCouponSystemType.Items
            If (lstItem.Checked) Then
                itemChecked = True
                Exit For
            End If
        Next

        If (cboCreateCouponWeldMachine.Text = "") Then
            MsgBox("Weld Machine cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.cboCreateCouponWeldMachine.SelectedIndex = 0
            Me.cboCreateCouponWeldMachine.Refresh()
            Return
        End If

        If (txtCreateCouponBarcode.Text = "") Then
            MsgBox("Barcode cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (cboCreateCouponMaterial.Text = "") Then
            MsgBox("Material cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (cboCreateCouponSize.Text = "") Then
            MsgBox("Size cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (cboCreateCouponThickness.Text = "") Then
            MsgBox("Thickness cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (cboCreateCouponJointType1.Text = "" Or cboCreateCouponJointType2.Text = "") Then
            MsgBox("Joint Type cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        'If (cboCreateCouponHeat1.Text = "" Or cboCreateCouponHeat2.Text = "") Then
        'MsgBox("Heat Number cannot be blank.", MsgBoxStyle.Information, "Error")
        'Me.tabCreateCoupon.SelectedIndex = 0
        'Me.tabCreateCoupon.Refresh()
        'Return
        'End If

        If (itemChecked = False) Then
            MsgBox("System Type have to check at least one.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 1
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        Dim coax As String = ""
        If chkCreateCouponCoax.Checked = True Then
            isCoax = "T"
            coax = cboCreateCouponCoax.Text
        End If

        If rdoCreateCouponPipe.Checked = True Then
            pipeTube = "PIPE"
        ElseIf rdoCreateCouponTube.Checked = True Then
            pipeTube = "TUBE"
        End If

        Dim heatId1 As String = ""
        Dim heatName1 As String = cboCreateCouponHeat1.Text
        Dim heatId2 As String = ""
        Dim heatName2 As String = cboCreateCouponHeat2.Text

        Dim dtResult As New DataTable
        dtResult = findHeatNos(Nothing, cboCreateCouponHeat1.Text)
        If dtResult.Rows.Count > 0 Then
            heatId1 = dtResult.Rows(0).Item("HEAT_NUMBER_ID")
        End If

        dtResult = findHeatNos(Nothing, cboCreateCouponHeat2.Text)
        If dtResult.Rows.Count > 0 Then
            heatId2 = dtResult.Rows(0).Item("HEAT_NUMBER_ID")
        End If

        Dim jointTypeCode1 As String = ""
        Dim jointTypeName1 As String = cboCreateCouponJointType1.Text
        Dim jointTypeCode2 As String = ""
        Dim jointTypeName2 As String = cboCreateCouponJointType2.Text

        dtResult = findJointTypes(cboCreateCouponJointType1.Text)
        If dtResult.Rows.Count > 0 Then
            jointTypeCode1 = dtResult.Rows(0).Item("JOINT_TYPE_CODE")
        End If

        dtResult = findJointTypes(cboCreateCouponJointType2.Text)
        If dtResult.Rows.Count > 0 Then
            jointTypeCode2 = dtResult.Rows(0).Item("JOINT_TYPE_CODE")
        End If

        Dim weldMachineId As String = ""
        dtResult = findWeldMachines(_PROJECT_ID, cboCreateCouponWeldMachine.Text)
        If dtResult.Rows.Count > 0 Then
            weldMachineId = dtResult.Rows(0).Item("WELD_MACHINE_ID")
        End If

        If btnSaveCoupon.Text = Globals.BUTTON_LABEL_SAVE Then
            returnExecute = doCreateCoupon(_USER_ID, coax, _PROJECT_ID, cboCreateCouponMaterial.Text, cboCreateCouponSize.Text, cboCreateCouponThickness.Text, isCoax, pipeTube, Globals.COUPON_TYPE_IN, heatId1, heatName1, heatId2, heatName2, lvCouponSystemType, "", txtCreateCouponBarcode.Text, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2, weldMachineId, cboCreateCouponWeldMachine.Text)
        ElseIf btnSaveCoupon.Text = Globals.BUTTON_LABEL_REDO Then
            returnExecute = doCreateCoupon(_USER_ID, coax, _PROJECT_ID, cboCreateCouponMaterial.Text, cboCreateCouponSize.Text, cboCreateCouponThickness.Text, isCoax, pipeTube, Globals.COUPON_TYPE_IN, heatId1, heatName1, heatId2, heatName2, lvCouponSystemType, _COUPON_BARCODE, txtCreateCouponBarcode.Text, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2, weldMachineId, cboCreateCouponWeldMachine.Text)
        ElseIf btnSaveCoupon.Text = Globals.BUTTON_LABEL_UPDATE Then
            returnExecute = doUpdateCoupon(_USER_ID, _COUPON_ID, coax, cboCreateCouponMaterial.Text, cboCreateCouponSize.Text, cboCreateCouponThickness.Text, isCoax, pipeTube, heatId1, heatName1, heatId2, heatName2, lvCouponSystemType, txtCreateCouponBarcode.Text, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2, weldMachineId, cboCreateCouponWeldMachine.Text, _COUPON_BARCODE)
        End If

        If returnExecute = True Then
            MsgBox(_SAVE_SUCCESSFUL_MESSAGE, MsgBoxStyle.Information, "EQAM")

            _FROM_SCREEN_ID = _SCREEN_ID
            _SCREEN_ID = SCREEN_COUPON_LIST

            frmCouponList.Show()
            frmCouponList.initScreen()
            Me.Hide()
        Else
            'MessageBox.Show("Error!")
            Return
        End If
    End Sub

    Private Sub btnCancelCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelCoupon.Click
        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = SCREEN_COUPON_LIST

        If (Globals.USER_ROLE_WELDER = _USER_ROLE) Then
            frmCouponList.Show()
            frmCouponList.initScreen()
        ElseIf (Globals.USER_ROLE_ENGINEER = _USER_ROLE) Then
            frmEngineerCoupon.Show()
            frmEngineerCoupon.initScreen()
        End If
        
        Me.Hide()
    End Sub

    Public Function doUpdateCoupon(ByVal userId As String, ByVal couponId As String, ByVal coax As String, ByVal material As String, ByVal size As String, ByVal thickness As String, ByVal isCoax As String, ByVal pipeTube As String, ByVal heatId1 As String, ByVal heatName1 As String, ByVal heatId2 As String, ByVal heatName2 As String, ByVal lv As Windows.Forms.ListView, ByVal barcode As String, ByVal jointTypeCode1 As String, ByVal jointTypeName1 As String, ByVal jointTypeCode2 As String, ByVal jointTypeName2 As String, ByVal weldMachineId As String, ByVal weldMachineName As String, ByVal couponBarcode As String) As Boolean
        Dim conn As New SqlCeConnection()
        Dim cmd As SqlCeCommand
        Dim sqlCeTransaction As SqlCeTransaction
        Dim SQL As String = ""
        Dim success As Boolean

        Try
            conn = New SqlCeConnection(sCon)

            If conn.State = ConnectionState.Closed Then
                conn.Open()
            End If

            Dim paramList As New Hashtable()

            sqlCeTransaction = conn.BeginTransaction
            cmd = conn.CreateCommand
            cmd.CommandText = "UPDATE eqam_coupon SET DATE_UPDATE = @DATE_UPDATE, TIME_UPDATE = @TIME_UPDATE, UPDATE_BY = @UPDATE_BY" & _
                            ", PIPE_TUBE = @PIPE_TUBE, IS_COAX = @IS_COAX, COAX = @COAX" & _
                            ", MATERIAL = @MATERIAL, SIZE = @SIZE, THICKNESS = @THICKNESS" & _
                            ", HEAT_NUMBER_ID_1 = @HEAT_NUMBER_ID_1, HEAT_NUMBER_NAME_1 = @HEAT_NUMBER_NAME_1" & _
                            ", HEAT_NUMBER_ID_2 = @HEAT_NUMBER_ID_2, HEAT_NUMBER_NAME_2 = @HEAT_NUMBER_NAME_2, BARCODE = @BARCODE" & _
                            ", JOINT_TYPE_CODE_1 = @JOINT_TYPE_CODE_1, JOINT_TYPE_NAME_1 = @JOINT_TYPE_NAME_1, JOINT_TYPE_CODE_2 = @JOINT_TYPE_CODE_2, JOINT_TYPE_NAME_2 = @JOINT_TYPE_NAME_2, WELD_MACHINE_ID = @WELD_MACHINE_ID, WELD_MACHINE_NAME = @WELD_MACHINE_NAME" & _
                            " WHERE COUPON_ID = @COUPON_ID"

            Dim currentDate As Decimal = PdaUtils.getCurrentDate
            Dim currentTime As Decimal = PdaUtils.getCurrentTime

            ' 1st line
            cmd.Parameters.AddWithValue("@DATE_UPDATE", currentDate)
            cmd.Parameters.AddWithValue("@TIME_UPDATE", currentTime)
            cmd.Parameters.AddWithValue("@UPDATE_BY", _USER_ID)

            ' 2nd line
            cmd.Parameters.AddWithValue("@PIPE_TUBE", pipeTube)
            cmd.Parameters.AddWithValue("@IS_COAX", isCoax)
            cmd.Parameters.AddWithValue("@COAX", coax)

            ' 3nd line
            cmd.Parameters.AddWithValue("@MATERIAL", material)
            cmd.Parameters.AddWithValue("@SIZE", size)
            cmd.Parameters.AddWithValue("@THICKNESS", thickness)

            cmd.Parameters.AddWithValue("@HEAT_NUMBER_ID_1", heatId1)
            cmd.Parameters.AddWithValue("@HEAT_NUMBER_NAME_1", heatName1)
            cmd.Parameters.AddWithValue("@HEAT_NUMBER_ID_2", heatId2)
            cmd.Parameters.AddWithValue("@HEAT_NUMBER_NAME_2", heatName2)
            cmd.Parameters.AddWithValue("@BARCODE", barcode)

            cmd.Parameters.AddWithValue("@JOINT_TYPE_CODE_1", jointTypeCode1)
            cmd.Parameters.AddWithValue("@JOINT_TYPE_NAME_1", jointTypeName1)
            cmd.Parameters.AddWithValue("@JOINT_TYPE_CODE_2", jointTypeCode2)
            cmd.Parameters.AddWithValue("@JOINT_TYPE_NAME_2", jointTypeName2)
            cmd.Parameters.AddWithValue("@WELD_MACHINE_ID", weldMachineId)
            cmd.Parameters.AddWithValue("@WELD_MACHINE_NAME", weldMachineName)

            cmd.Parameters.AddWithValue("@COUPON_ID", couponId)

            'cmd.CommandTimeout = 1800
            cmd.Transaction = sqlCeTransaction
            cmd.ExecuteNonQuery()

            cmd = conn.CreateCommand
            cmd.CommandText = "DELETE FROM eqam_coupon_system WHERE COUPON_BARCODE = @COUPON_BARCODE"
            cmd.Parameters.AddWithValue("@COUPON_BARCODE", couponBarcode)
            cmd.Transaction = sqlCeTransaction
            cmd.ExecuteNonQuery()

            ' save coupon system
            Dim lstItem As ListViewItem
            For Each lstItem In lv.Items
                If (lstItem.Checked) Then
                    Dim systemId As String = lstItem.Tag

                    Dim sqlCouponSystem As String = "INSERT INTO eqam_coupon_system " & _
                    " (COUPON_BARCODE, SYSTEM_TYPE_ID, PDA_CODE, ADD_BY, DATE_ADD, TIME_ADD, DATE_UPDATE, TIME_UPDATE, UPDATE_BY)" & _
                    " VALUES (@COUPON_BARCODE, @SYSTEM_TYPE_ID, @PDA_CODE, @ADD_BY, @DATE_ADD, @TIME_ADD, @DATE_UPDATE, @TIME_UPDATE, @UPDATE_BY)"
                    cmd = conn.CreateCommand
                    cmd.CommandText = sqlCouponSystem
                    cmd.Parameters.AddWithValue("@COUPON_BARCODE", couponBarcode)
                    cmd.Parameters.AddWithValue("@SYSTEM_TYPE_ID", systemId)
                    cmd.Parameters.AddWithValue("@PDA_CODE", _PDA_CODE)
                    cmd.Parameters.AddWithValue("@ADD_BY", _USER_ID)
                    cmd.Parameters.AddWithValue("@DATE_ADD", currentDate)
                    cmd.Parameters.AddWithValue("@TIME_ADD", currentTime)
                    cmd.Parameters.AddWithValue("@DATE_UPDATE", currentDate)
                    cmd.Parameters.AddWithValue("@TIME_UPDATE", currentTime)
                    cmd.Parameters.AddWithValue("@UPDATE_BY", _USER_ID)

                    cmd.Transaction = sqlCeTransaction
                    cmd.ExecuteNonQuery()
                End If
            Next

            _SAVE_SUCCESSFUL_MESSAGE = "Update Successfully."
            sqlCeTransaction.Commit()
            success = True
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, sysname & " - ex")
            MsgBox("LOCAL CONNECTION UPDATE COUPON: " & vbCrLf & ex.Message, MsgBoxStyle.Information, sysname & " - ExecuteSQL")
            sqlCeTransaction.Rollback()
            success = False
        Finally
            If conn.State = ConnectionState.Open Then conn.Close()
        End Try
        Return success
    End Function

    Private Sub chkCreateCouponCoax_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCreateCouponCoax.CheckStateChanged
        If chkCreateCouponCoax.Checked = True Then
            cboCreateCouponCoax.Enabled = True
        Else
            cboCreateCouponCoax.Enabled = False
            'cboCreateCouponCoax.Text = ""
        End If
    End Sub

    Private Sub frmCreateCoupon_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub MenuItemLogOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemLogOut.Click
        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = SCREEN_PROJECT

        frmProject.Show()
        frmProject.initScreen()
        Me.Hide()
    End Sub

    Private Sub MenuItemCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemMenu.Click
        frmMenu.Show()
        frmMenu.initScreen()
        Me.Hide()
    End Sub

    Private Sub cboCreateCouponSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCreateCouponSize.SelectedIndexChanged
        If (cboCreateCouponSize.Text <> "" And cboCreateCouponJointType1.Text() <> "") Then
            Dim heatNumber As String = fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboCreateCouponSize.Text, cboCreateCouponJointType1.Text)
            cboCreateCouponHeat1.Text = heatNumber
        End If
        If (cboCreateCouponSize.Text <> "" And cboCreateCouponJointType2.Text() <> "") Then
            Dim heatNumber As String = fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboCreateCouponSize.Text, cboCreateCouponJointType2.Text)
            cboCreateCouponHeat2.Text = heatNumber
        End If
    End Sub

    Private Sub cboCreateCouponJointType1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCreateCouponJointType1.SelectedIndexChanged
        If (cboCreateCouponSize.Text <> "" And cboCreateCouponJointType1.Text() <> "") Then
            Dim heatNumber As String = fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboCreateCouponSize.Text, cboCreateCouponJointType1.Text)
            cboCreateCouponHeat1.Text = heatNumber
        End If
    End Sub

    Private Sub cboCreateCouponJointType2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCreateCouponJointType2.SelectedIndexChanged
        If (cboCreateCouponSize.Text <> "" And cboCreateCouponJointType2.Text() <> "") Then
            Dim heatNumber As String = fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboCreateCouponSize.Text, cboCreateCouponJointType2.Text)
            cboCreateCouponHeat2.Text = heatNumber
        End If
    End Sub

    Private Sub btnDeleteCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteCoupon.Click
        Dim list As New ArrayList
        If MsgBox("Are you sure want to delete?", MsgBoxStyle.YesNo, "E-QAM") = vbYes Then                        
            Dim conn As New SqlCeConnection()
            Dim cmd As SqlCeCommand
            Dim sqlCeTransaction As SqlCeTransaction
            Dim SQL As String = ""
            Dim success As Boolean

            Try
                conn = New SqlCeConnection(sCon)

                If conn.State = ConnectionState.Closed Then
                    conn.Open()
                End If

                Dim paramList As New Hashtable()

                sqlCeTransaction = conn.BeginTransaction

                cmd = conn.CreateCommand
                cmd.CommandText = "DELETE FROM eqam_coupon WHERE COUPON_ID = @COUPON_ID"
                cmd.Parameters.AddWithValue("@COUPON_ID", _COUPON_ID)
                cmd.Transaction = sqlCeTransaction
                cmd.ExecuteNonQuery()

                MsgBox("DELETE COUPON SUCCESSFULLY", MsgBoxStyle.Information, "EQAM")

                _FROM_SCREEN_ID = _SCREEN_ID
                _SCREEN_ID = SCREEN_COUPON_LIST

                frmEngineerCoupon.Show()
                frmEngineerCoupon.initScreen()
                Me.Hide()
                sqlCeTransaction.Commit()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Information, sysname & " - ex")
                MsgBox("LOCAL CONNECTION DELETE COUPON: " & vbCrLf & ex.Message, MsgBoxStyle.Information, sysname & " - ExecuteSQL")
                sqlCeTransaction.Rollback()
                success = False
            Finally
                If conn.State = ConnectionState.Open Then conn.Close()
            End Try
        End If
    End Sub
End Class